<template>
  <UserSelectModal modalTitle="请选择参与人" rowKey="id" @register="registerSelUserModal" @getSelectResult="handleSelectResult" showSelected />
</template>
<script lang="ts" setup>
  import { ref } from 'vue';
  import { useModal } from '/@/components/Modal';
  import { useMessage } from '/@/hooks/web/useMessage';
  import UserSelectModal from '/@/components/Form/src/jeecg/components/modal/UserSelectModal.vue';
  import { addCandidate } from '../processtask.api';

  // 声明Emits
  const emit = defineEmits(['select', 'register']);

  // 注册委托用户选择 modal
  const [registerSelUserModal, selUserModal] = useModal();

  // 当前记录
  const currentRecord: any = ref({});

  const { createMessage } = useMessage();

  // 选择委办用户成功
  async function handleSelectResult(options, userIdList) {
    if (userIdList.length > 0) {
      try {
        const res = await addCandidate({
          processTaskId: currentRecord.value.id,
          processInstanceId: currentRecord.value.processInstanceId,
          actorIds: userIdList,
        });
        if (res && res.success) {
          createMessage.success('提交成功');
          //刷新列表
          emit('select', userIdList);
        }
      } finally {
      }
    }
  }

  defineExpose({
    show(record) {
      currentRecord.value = record;
      selUserModal.openModal(true);
    },
  });
</script>
